package com.happy.second.Controller;

import com.happy.second.Entity.User;
import com.happy.second.Service.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author itoutsource.cz10
 */
@RestController
public class WelcomeController {

    private static final Logger log= LoggerFactory.getLogger(WelcomeController.class);

    @Autowired
    private UserService userService;

    @RequestMapping(value = "/welcome/{name}", method = RequestMethod.GET)
    public String welcome(@PathVariable(value = "name") String name) {
        log.info("welcome");
        return "welcome " + name;
    }


    @RequestMapping(value = "/update", method = RequestMethod.PUT)
    public String update(@RequestBody User user) {
        log.error("这是一个简单的错误");
        return "welcome "+user.getClass().getName();
    }

    @RequestMapping(value = "/user/{id}", method = RequestMethod.GET)
    public User getUser(@PathVariable(value = "id") int id) {
        User user=userService.selectByPrimary(id);
        log.info("userInfo"+user.toString());
        return user;
    }

}
